package com.example.shop.api;

import com.example.shop.base.ApiBaseController;
import com.example.shop.base.BaseController;
import com.example.shop.base.Result;
import com.example.shop.commodity.entity.ShopCategorys;
import com.example.shop.commodity.service.ShopCategorysService;
import com.example.shop.common.annotation.LoginIgnore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "/api/shop/category")
public class ApiShopCategorysController extends ApiBaseController {

    @Autowired
    private ShopCategorysService categorysService;

    /**
     * 分类列表
     *
     * @param category
     * @return
     */
    @GetMapping("/list")
    @LoginIgnore
    public Result list(ShopCategorys category) {
        List<Map<String, Object>> list = new ArrayList<>();

        Map<String, Object> map = null;
        List<ShopCategorys> categorysList = categorysService.findList(category);
        for (ShopCategorys categorys : categorysList) {
            map = new HashMap<>();
            map.put("id", categorys.getId());
            map.put("name", categorys.getName());
            map.put("icon", picture_url + categorys.getIcon());
            list.add(map);
        }
        return Result.success(list);
    }
}
